package com.ziyun.pop.modules.production.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ziyun.pop.common.e.DeleteEnum;
import com.ziyun.pop.modules.production.dao.ErpOrderItemDao;
import com.ziyun.pop.modules.production.entity.ErpOrderItemEntity;
import com.ziyun.pop.modules.production.service.ErpOrderItemService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;


@Service("erpOrderItemService")
public class ErpOrderItemServiceImpl extends ServiceImpl<ErpOrderItemDao, ErpOrderItemEntity> implements ErpOrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ErpOrderItemEntity> page = (Page<ErpOrderItemEntity>) this.page(
                new Query<ErpOrderItemEntity>(params).getPage(),
                new QueryWrapper<ErpOrderItemEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<ErpOrderItemEntity> selectListByErpOrder(String orderNo) {
        return baseMapper.selectList(new QueryWrapper<ErpOrderItemEntity>()
                .eq("order_no",orderNo)
                .eq("item_del", DeleteEnum.NOT_DELETE.toInt()));
    }

    @Override
    public ErpOrderItemEntity selectByItemId(Integer itemId) {
        return this.baseMapper.selectByItemId(itemId);
    }

    @Override
    public R queryErpOrderItemList(Map<String, Object> params) {
        String orderNo = (String) params.get("orderNo");

        List<ErpOrderItemEntity> erpOrderItemList = this.baseMapper.selectList(new QueryWrapper<>(new ErpOrderItemEntity())
                .eq(StringUtils.isNotBlank(orderNo), "order_no", orderNo)
                .eq("item_del", DeleteEnum.NOT_DELETE.toInt())
        );
        return R.ok().put("list", erpOrderItemList);
    }

    @Override
    public boolean updateByMap(Map<String, Object> updateMap, Integer eoItemId) {
        int count = baseMapper.updateByMap(updateMap, eoItemId);
        if (count == 0){
            return false;
        }
        return true;
    }

    @Override
    public boolean updateBatchByMap(Map<String, Object> updateMap, List<Integer> eoItemIds) {
        int count = baseMapper.updateBatchByMap(updateMap, eoItemIds);
        if (count == 0){
            return false;
        }
        return true;
    }

}
